package com.lei.ajax.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lei.ajax.service.UserService;
import com.lei.ajax.service.impl.UserServiceImpl;

public class UserServlet extends HttpServlet {
	private UserService userService = new UserServiceImpl();
//	@Override
//	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//		Set<String> set = new HashSet<>();
//		set.add("userName");
//
//		String userName = req.getParameter("userName");
//		// 用户名已经存在
//		if (set.contains(userName)) {
//			PrintWriter out = resp.getWriter();
//			out.print("exist");
//		}
//	}

	@Override
	protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
		arg0.setCharacterEncoding("UTF-8");
		arg1.setCharacterEncoding("UTF-8");
		String methon = arg0.getParameter("methon");
		if ("exit".equals(methon)) {
			exit(arg0, arg1);
		}
	}

	private void exit(HttpServletRequest arg0, HttpServletResponse arg1) {
//	Long id=Long.valueOf("userName");
		String userName = String.valueOf("userName");
		userService.getById(userName);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		PrintWriter out = resp.getWriter();
		out.print("register success");

	}

}
